﻿@{
    ViewBag.Title = "硅片切割";
}
@section SideNav{@Html.Partial("SideNavPartialView")}
<script src="~/Content/layer/laydate/laydate.js"></script>
<script src="~/Scripts/bootstrap-table-export.min.js"></script>
<script src="~/Scripts/table-export.min.js"></script>
<ol class="breadcrumb">
    <li><span class="glyphicon glyphicon-home"></span>  @Html.ActionLink("首页", "Index", "Home")</li>
    <li class="active">@Html.ActionLink("生产管理", "Index", "Workshop")</li>
    <li class="active">@Html.ActionLink("硅片切割", "Index", "SiliconCutting")</li>
</ol>
<div id="droplist" style="display:none">
    @Html.DropDownList("condition", ViewBag.Attrs as List<SelectListItem>, new { @class = "btn btn-default dropdown-toggle" })
</div>
<div class="form-group" id="conditions">
    <div class="form-inline">
        起始时间:<input class="laydate-icon form-control" id="start" style="width:20%; height:34px;">
        结束时间:<input class="laydate-icon form-control" id="end" style="width: 20%; height: 34px;">
        <input type="button" id="btnAnalysis" value="分析结果" class="btn btn-default" />
        <input type="button" id="btnExport" value="一键导出" class="btn btn-success" />
    </div>
    <p></p>
</div>
<input type="button" id="btnSearch" value="检索" class="btn btn-default" />
<input type="button" class="btn btn-primary btn-group-xs" value="增加检索条件" id="btn_addCondition" />
<input type="button" id="btnhidden" value="关闭分析图表" class="btn btn-danger" onclick="javascript: document.getElementById('echarts').style.display = 'none';" style="display:none" />
<input type="button" id="btnshow" value="打开分析图表" class="btn btn-default" onclick="javascript: document.getElementById('echarts').style.display = 'block';" style="display: none" />
<input type="button" id="btnConfig" value="配置显示字段" class="btn btn-info" data-toggle="modal" data-target="#ConfigModel" />
<div id="echarts" style="display: none">
    <div id="bar" style="width: 800px;height:600px;"></div>
    <div id="pie" style="width: 800px;height:600px;"></div>
</div>
<table id="siliconcuttinggrid"></table>
<!-- 模态框（Modal） -->
<div class="modal fade" id="ConfigModel" tabindex="-1" role="dialog" aria-labelledby="ConfigModelLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="ModalLabel">选择字段</h4>
            </div>
            <div class="modal-body">
                <table border="0" width="500">
                    <tr>
                        <td width="40%">
                            <select style="width:100%" multiple size="12" name="list1" id="list1" ondblclick="moveOption(document.getElementById('list1'), document.getElementById('list2'))">
                                @{
                                    if (ViewBag.UnHasConfigs == null)
                                    {
                                        foreach (var item in ViewBag.Attrs as List<SelectListItem>)
                                        {
                                            <option value="@item.Value">@item.Text</option>
                                        }
                                    }
                                    else
                                    {
                                        foreach (var item in ViewBag.UnHasConfigs as List<SelectListItem>)
                                        {
                                            <option value="@item.Value">@item.Text</option>
                                        }
                                    }
                                    
                                }
                            </select>

                        </td>
                        <td width="20%" align="center">
                            <input type="button" value=">>" class="btn btn-primary"  onclick="moveOption(document.getElementById('list1'), document.getElementById('list2'))">
                            <br />
                            <br />
                            <input type="button" value="<<" class="btn btn-danger" onclick="moveOption(document.getElementById('list2'), document.getElementById('list1'))">
                        </td>
                        <td width="40%">
                            @{
                                if (ViewBag.HasConfigs == null)
                                {
                                    <select style="width: 100%" multiple name="list2" size="12" id="list2" ondblclick="moveOption(document.getElementById('list2'), document.getElementById('list1'))"></select>        
                                }
                                else
                                {
                                    <select style="width: 100%" multiple name="list2" size="12" id="list2" ondblclick="moveOption(document.getElementById('list2'), document.getElementById('list1'))">
                                        @foreach(var item in ViewBag.HasConfigs as List<SelectListItem>)
                                        {
                                            <option value="@item.Value">@item.Text</option>
                                        }
                                    </select>
                                }
                            }
                        </td>                  
                    </tr>
                </table>
                <input type="text" id="configs" value="" style="display:none" />
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" id="saveConfig">提交更改</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<!-- 模态框结束 -->
<script type="text/javascript">
    function isContains(str, substr) {
        var res = new RegExp(substr).test(str);
        return res;
    }
    var configColumns = "@ViewBag.configs";
    var columnsContent = null;
    var hasconfig = 0;
    
    if (configColumns && configColumns.length > 0) {
        columnsContent = [
                   { title: "ID", field: "SiliconCuttingID" },
                   { title: "切片质量ID", field: "SliceQualityID", visible: isContains(configColumns, "SliceQualityID") ? true : false },
                   { title: "车间号", field: "WorkshopID", visible: isContains(configColumns, "WorkshopID") ? true : false },
                   { title: "班组", field: "TeamID", formatter: function (value, row, index) { return row.Team.Name }, visible: isContains(configColumns, "TeamID") ? true : false },
                   { title: "线锯编号", field: "EquipmentFileID", formatter: function (value, row, index) { return row.EquipmentFile.Name }, visible: configColumns.indexOf("EquipmentFileID") > 0 ? true : false },
                   { title: "切割序号", field: "CuttingID", visible: isContains(configColumns, "CuttingID") ? true : false },
                   { title: "切割编号", field: "CuttingNum", visible: isContains(configColumns, "CuttingNum") ? true : false },
                   { title: "切割块数", field: "CuttingBlock", visible: isContains(configColumns, "CuttingBlock") ? true : false },
                   { title: "切割长度", field: "CuttingLength", visible: isContains(configColumns, "CuttingLength") ? true : false },
                   { title: "底料长度", field: "BottomMaterialLength", visible: isContains(configColumns, "BottomMaterialLength") ? true : false },
                   { title: "切割规格", field: "CuttingSpecification", visible: isContains(configColumns, "CuttingSpecification") ? true : false },
                   { title: "切割厚度", field: "CuttingThickness", visible: isContains(configColumns, "CuttingThickness") ? true : false },
                   { title: "切割类型", field: "CuttingType", visible: isContains(configColumns, "CuttingType") ? true : false },
                   { title: "钢线编号", field: "SteelWireID", visible: isContains(configColumns, "SteelWireID") ? true : false },
                   { title: "槽距", field: "SlotPitch", visible: isContains(configColumns, "SlotPitch") ? true : false },
                   { title: "碳化硅编号", field: "SiliconCarbideID", visible: isContains(configColumns, "SiliconCarbideID") ? true : false },
                   { title: "悬浮液编号", field: "SuspensionID", visible: isContains(configColumns, "SuspensionID") ? true : false },
                   { title: "浆料开始密度", field: "PulpDensityStart", visible: isContains(configColumns, "PulpDensityStart") ? true : false },
                   { title: "浆料结束密度", field: "PulpDensityEnd", visible: isContains(configColumns, "PulpDensityEnd") ? true : false },
                   { title: "浆料更新量", field: "PulpUpdateCount", visible: isContains(configColumns, "PulpUpdateCount") ? true : false },
                   { title: "导轮刀数", field: "GuideNum", visible: isContains(configColumns, "GuideNum") ? true : false },
                   { title: "是否发生断线", field: "IsBreaked", visible: isContains(configColumns, "IsBreaked") ? true : false },
                   { title: "断线情况编号", field: "BreakedID", visible: isContains(configColumns, "BreakedID") ? true : false },
                   { title: "是否报废", field: "IsScrap", visible: isContains(configColumns, "IsScrap") ? true : false },
                   { title: "是否测试", field: "IsTest", visible: isContains(configColumns, "IsTest") ? true : false },
                   { title: "清洗设备编号", field: "CleaningEquipmentNum", visible: isContains(configColumns, "CleaningEquipmentNum") ? true : false },
                   { title: "预清洗设备编号", field: "Pre_CleaningEquipmentNum", visible: isContains(configColumns, "Pre_CleaningEquipmentNum") ? true : false },
                   { title: "备注", field: "Remark", visible: isContains(configColumns, "Remark") ? true : false },
                   { title: "一级品数量", field: "LevelOneCount", visible: isContains(configColumns, "LevelOneCount") ? true : false },
                   { title: "二级品数量", field: "LevelTwoCount", visible: isContains(configColumns, "LevelTwoCount") ? true : false },
                   { title: "三级品数量", field: "LevelThreeCount", visible: isContains(configColumns, "LevelThreeCount") ? true : false },
                   { title: "合格品数量", field: "QualifiedCount", visible: isContains(configColumns, "QualifiedCount") ? true : false },
                   { title: "不合格数量", field: "UnqualifiedCount", visible: isContains(configColumns, "UnqualifiedCount") ? true : false },
                   { title: "碎片重量", field: "DebrisWeight", visible: isContains(configColumns, "DebrisWeight") ? true : false },
                   { title: "合计数量", field: "SumCount", visible: isContains(configColumns, "SumCount") ? true : false },
                   { title: "合格率", field: "QualifiedRate", visible: isContains(configColumns, "QualifiedRate") ? true : false },
                   { title: "不合格数量", field: "UnqualifiedCount", visible: isContains(configColumns, "UnqualifiedCount") ? true : false },
                   { title: "经办人", field: "Handler", visible: isContains(configColumns, "Handler") ? true : false },
                   { title: "一级品理论数量", field: "LevelOneTheoreticalCount", visible: isContains(configColumns, "LevelOneTheoreticalCount") ? true : false },
                   { title: "抽检数量", field: "SpotCheckCount", visible: isContains(configColumns, "SpotCheckCount") ? true : false },
                   { title: "抽检不合格数量", field: "SpotCheckUnqualifiedCount", visible: isContains(configColumns, "SpotCheckUnqualifiedCount") ? true : false },
                   { title: "抽检备注", field: "SpotCheckRemark", visible: isContains(configColumns, "SpotCheckRemark") ? true : false },
                   { title: "是否审核", field: "IsCheck", visible: isContains(configColumns, "IsCheck") ? true : false },
                   { title: "审核人", field: "Checker", visible: isContains(configColumns, "Checker") ? true : false },
                   { title: "是否抽检", field: "IsSpotCheck", visible: isContains(configColumns, "IsSpotCheck") ? true : false },
                   { title: "抽检审核人", field: "SpotChecker", visible: isContains(configColumns, "SpotChecker") ? true : false },
                   { title: "员工编号", field: "EmployeeNum", visible: isContains(configColumns, "EmployeeNum") ? true : false },
                   { title: "计入考核", field: "IsIncludedAssessment", visible: isContains(configColumns, "IsIncludedAssessment") ? true : false },
                   { title: "切割时间", field: "CuttingDate", formatter: function (value) { return moment(value).format("YYYY-MM-DD HH:mm:ss") }, visible: configColumns.indexOf("CuttingDate") > 0 ? true : false },
                   {
                       title: "操作", field: "SiliconCuttingID", formatter: function (value) {
                           return "<a class='btn btn-sm btn-primary' href ='#' data-method='Detail' data-value=" + value + ">详情</a>"
                       }
                   }
        ];
        hasconfig = 1;
    }
    else {
        columnsContent = [
               { title: "ID", field: "SiliconCuttingID" },
               { title: "切片质量ID", field: "SliceQualityID", visible: false },
               { title: "车间号", field: "WorkshopID", visible: false },
               { title: "班组", field: "TeamID", formatter: function (value, row, index) { return row.Team.Name } },
               { title: "线锯编号", field: "EquipmentFileID", formatter: function (value, row, index) { return row.EquipmentFile.Name } },
               { title: "切割序号", field: "CuttingID", visible: false },
               { title: "切割编号", field: "CuttingNum" },
               { title: "切割块数", field: "CuttingBlock", visible: false },
               { title: "切割长度", field: "CuttingLength", visible: false },
               { title: "底料长度", field: "BottomMaterialLength", visible: false },
               { title: "切割规格", field: "CuttingSpecification", visible: false },
               { title: "切割厚度", field: "CuttingThickness", visible: false },
               { title: "切割类型", field: "CuttingType" },
               { title: "钢线编号", field: "SteelWireID", visible: false },
               { title: "槽距", field: "SlotPitch", visible: false },
               { title: "碳化硅编号", field: "SiliconCarbideID", visible: false },
               { title: "悬浮液编号", field: "SuspensionID", visible: false },
               { title: "浆料开始密度", field: "PulpDensityStart", visible: false },
               { title: "浆料结束密度", field: "PulpDensityEnd", visible: false },
               { title: "浆料更新量", field: "PulpUpdateCount", visible: false },
               { title: "导轮刀数", field: "GuideNum", visible: false },
               { title: "是否发生断线", field: "IsBreaked", visible: false },
               { title: "断线情况编号", field: "BreakedID", visible: false },
               { title: "是否报废", field: "IsScrap", visible: false },
               { title: "是否测试", field: "IsTest", visible: false },
               { title: "清洗设备编号", field: "CleaningEquipmentNum", visible: false },
               { title: "预清洗设备编号", field: "Pre_CleaningEquipmentNum", visible: false },
               { title: "备注", field: "Remark", visible: false },
               { title: "一级品数量", field: "LevelOneCount", visible: false },
               { title: "二级品数量", field: "LevelTwoCount", visible: false },
               { title: "三级品数量", field: "LevelThreeCount", visible: false },
               { title: "合格品数量", field: "QualifiedCount", visible: false },
               { title: "不合格数量", field: "UnqualifiedCount", visible: false },
               { title: "碎片重量", field: "DebrisWeight", visible: false },
               { title: "合计数量", field: "SumCount", visible: false },
               { title: "合格率", field: "QualifiedRate", visible: false },
               { title: "不合格数量", field: "UnqualifiedCount", visible: false },
               { title: "经办人", field: "Handler", visible: false },
               { title: "一级品理论数量", field: "LevelOneTheoreticalCount", visible: false },
               { title: "抽检数量", field: "SpotCheckCount", visible: false },
               { title: "抽检不合格数量", field: "SpotCheckUnqualifiedCount", visible: false },
               { title: "抽检备注", field: "SpotCheckRemark", visible: false },
               { title: "是否审核", field: "IsCheck", visible: false },
               { title: "审核人", field: "Checker", visible: false },
               { title: "是否抽检", field: "IsSpotCheck", visible: false },
               { title: "抽检审核人", field: "SpotChecker", visible: false },
               { title: "员工编号", field: "EmployeeNum" },
               { title: "计入考核", field: "IsIncludedAssessment", visible: false },
               { title: "切割时间", field: "CuttingDate", formatter: function (value) { return moment(value).format("YYYY-MM-DD HH:mm:ss") } },
               {
                   title: "操作", field: "SiliconCuttingID", formatter: function (value) {
                       return "<a class='btn btn-sm btn-primary' href ='#' data-method='Detail' data-value=" + value + ">详情</a>"
                   }
               }
        ];
        hasconfig = 0;
    }
</script>
<script type="text/javascript">
    var flag = 0;
    $('#btn_addCondition').click(function () {
        var html = $('#droplist').html();
        $('#conditions').append("<div class='form-inline'>" + html + " <input id='search' type='text' name='QueryString' class='form-control' placeholder='输入检索词' /> <input type='button' class='btn btn-danger btn-group-xs' value='-' onclick='removeCondition(this)'/></div><p></p>");
    });

    $('#btnAnalysis').click(function () {
        $.getJSON('@Url.Action("virableList")', function (json) {
            $('#btnhidden').show();
            $('#btnshow').show();
            //if (flag == 0) {
            //    getecharts(json);
            //    flag = 1;
            //}
            getecharts(json);
            layer.tab({
                area: ['400px', '500px'],
                tab: [{
                    title: '报表汇总',
                    content: '<br>切割次数：' + json[0]["cuttingCount"] + '次<br>断线次数：' + json[0]["breakedCount"] + "次<br>切割硅块数量：" +
                       json[0]["siliconBlockCount"] + "块<br>总有效切割长度：" + json[0]["siliconLength"] + "mm<br>平均有效切割长度：" + json[0]["aveSiliconLength"] +
                       "mm<br>切割硅块总长度：" + json[0]["sumSiliconCuttingLength"] + "mm<br>平均切割硅块长度：" + json[0]["aveSiliconCuttingLength"] +
                       "mm<br>硅片切割数量：" + json[0]["sumCuttingSiliconPiaceCount"] + "片<br>硅片合格数量：" + json[0]["sumQualifiedCount"] +
                       "片<br>硅片合格率：" + json[0]["sumQualifiedRate"] + "%<br>A级品率：" + json[0]["AQualifiedRate"] + "%<br>平均单锭出片数(25块)：" +
                       json[0]["aveSingleCount"] + "片<br>线锯开机率：" + json[0]["lineStartRate"] + "刀/天<br>"
                }, {
                    title: '质量情况',
                    content: '<b color="red"><font color="red">不合格部分</font></b><br>'
                        + '碎片-数量：' + (json[0]["Fragment"] ? json[0]["Fragment"] : "-") + '，比率：' + (json[0]["FragmentRate"] ? json[0]["FragmentRate"] : "-") + "%<br>"
                        + '厚度偏差片-数量：' + (json[0]["ThicknessDeviation"] ? json[0]["ThicknessDeviation"] : "-") + '，比率：' + (json[0]["ThicknessDeviationRate"] ? json[0]["ThicknessDeviationRate"] : "-") + "%<br>"
                        + '缺口，掉脚-数量：' + (json[0]["Notch"] ? json[0]["Notch"] : "-") + '，比率：' + (json[0]["NotchRate"] ? json[0]["NotchRate"] : "-") + "<br>"
                        + 'TTV偏差整片-数量：' + (json[0]["TTV_Offset"] ? json[0]["TTV_Offset"] : "-") + '，比率：' + (json[0]["TTV_OffsetRate"] ? json[0]["TTV_OffsetRate"] : "-") + "%<br>"
                        + '杂质整片-数量：' + (json[0]["Impurity"] ? json[0]["Impurity"] : "-") + '，比率：' + (json[0]["ImpurityRate"] ? json[0]["ImpurityRate"] : "-") + "<br>"
                        + '锯痕超差片-数量：' + (json[0]["UnqualifiedMark"] ? json[0]["UnqualifiedMark"] : "-") + '，比率：' + (json[0]["UnqualifiedMarkRate"] ? json[0]["UnqualifiedMarkRate"] : "-") + "%<br>"
                        + '晶粒不合格片-数量：' + (json[0]["UnqualifiedGrain"] ? json[0]["UnqualifiedGrain"] : "-") + '，比率：' + (json[0]["UnqualifiedGrainRate"] ? json[0]["UnqualifiedGrainRate"] : "-") + "%<br>"
                    + '<b><font color="green">合格部分</font></b><br>'
                        + 'A锯痕(0-20μm)-数量：' + (json[0]["MarkA"] ? json[0]["MarkA"] : "-") + '，比率：' + (json[0]["MarkARate"] ? json[0]["MarkARate"] : "-") + "%，级别 : 一级<br>"
                        + 'B2晶粒小-数量：' + (json[0]["B2"] ? json[0]["B2"] : "-") + '，比率：' + (json[0]["B2Rate"] ? json[0]["B2Rate"] : "-") + "%，级别 : 一级<br>"
                        + '胶面B4-数量：' + (json[0]["Glue"] ? json[0]["Glue"] : "-") + '，比率：' + (json[0]["GlueRate"] ? json[0]["GlueRate"] : "-") + "%，级别 : 二级<br>"
                        + 'B7(锯痕20～40μｍ)-数量：' + (json[0]["MarkB7"] ? json[0]["MarkB7"] : "-") + '，比率：' + (json[0]["MarkB7Rate"] ? json[0]["MarkB7Rate"] : "-") + "%，级别 : 二级<br>"
                        + 'B9表面少许沾污-数量：' + (json[0]["B9"] ? json[0]["B9"] : "-") + '，比率：' + (json[0]["B9Rate"] ? json[0]["B9Rate"] : "-") + "%，级别 : 二级<br>"
                        + 'B11色差片-数量：' + (json[0]["B11"] ? json[0]["B11"] : "-") + '，比率：' + (json[0]["B11Rate"] ? json[0]["B11Rate"] : "-") + "%，级别 : 二级<br>"
                        + 'B12色差片-数量：' + (json[0]["B12"] ? json[0]["B12"] : "-") + '，比率：' + (json[0]["B12Rate"] ? json[0]["B12Rate"] : "-") + "%，级别 : 二级<br>"

                }]
            })

        })
    });
    $('#saveConfig').click(function () {
        var config = document.getElementById('configs').value;
        var adminid = parseInt(@Session["AdminID"].ToString());
        var model = "ReportConfig";
        //layer.alert(config);
        var _url = hasconfig > 0 ? '@Url.Action("Modify","ReportConfig")' : '@Url.Action("Add","ReportConfig")';

        $.ajax({
            url: _url,
            type: 'post',
            data: { "config": config, "adminid": adminid, "model": model},
            success: function (data) {
                layer.msg(data.Message, { icon: 1 }, function () {
                    location.reload();
                });
            },
            error: function () {
                layer.msg("网络错误", { icon: 2 });
            }
        })
    })
    var keys = new Array();
    var values = new Array();
    //定义两个数组属性
    Array.prototype.indexOf = function (val) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] == val) return i;
        }
        return -1;
    };
    Array.prototype.remove = function (val) {
        var index = this.indexOf(val);
        if (index > -1) {
            this.splice(index, 1);
        }
    };

    $('#btnSearch').click(function () {
        var selected = $('#conditions .form-inline .dropdown-toggle');
        for (var i = 0; i < selected.length; i++) {
            keys.push(selected[i].value);
            var value = selected[i].parentNode.childNodes[3].value;
            values.push(value);
        }
        keys = unique(keys);
        values = unique(values);
        var $table = $('#siliconcuttinggrid');
        $table.bootstrapTable("refresh");
        keys.splice(0, keys.length);
        values.splice(0, values.length);
    });

    $(document).ready(function () {
        var $table = $('#siliconcuttinggrid');
        $table.bootstrapTable({
            toolbar: "#toolbar",
            showRefresh: true,
            showColumns: true,
            showExport: true,                     //是否显示导出
            exportDataType: "all",              //basic', 'all', 'selected'.
            pageNumber: 1,
            pageSize: 10,
            pagination: true,
            sidePagination: "server",
            pageList: "[5, 10, 20, 50, 100]",
            method: "post",
            url: "@Url.Action("PageList")",
            queryParams: queryParams,
            queryParamsType: "limit", //参数格式,发送标准的RESTFul类型的参数请求
            columns: columnsContent,
            onAll: function (name, args) {
                if ((name == "load-success.bs.table") || (name == "column-switch.bs.table")) {
                    //详情
                    $("a[data-method='Detail']").click(function () {
                        var id = $(this).attr("data-value");
                        var modifyDialog = new BootstrapDialog({
                            title: "<span class='glyphicon glyphicon-user'></span>详情(字段太多回头再填~)",
                            message: function (dialog) {
                                var $message = $('<div></div>');
                                var pageToLoad = dialog.getData('pageToLoad');
                                $message.load(pageToLoad);
                                return $message;
                            },
                            data: {
                                'pageToLoad': '@Url.Action("Modify")/' + id
                            },
                            buttons: [{
                                icon: "glyphicon glyphicon-plus",
                                label: "详情"
                            }, {
                                icon: "glyphicon glyphicon-remove",
                                label: "关闭",
                                action: function (dialogItself) {
                                    dialogItself.close();
                                }
                            }]
                        });
                        modifyDialog.open();
                    });
                    //详情结束
                }
            }
        });
    });
    function queryParams(params) {

        var temp = {
            pageNumber: params.offset,
            pageSize: params.limit,
            start: document.getElementById("start").value == "" ? "1999/01/01 00:00:00" : document.getElementById("start").value,
            end: document.getElementById("end").value == "" ? getNowFormatDate(0) : document.getElementById("end").value,
            objs: createJsonStr()
        };
        return temp;
    }

    function createJsonStr() {
        var json = {};
        var jsonStr = "";
        if (keys.length > 0) {
            for (var i = 0; i < keys.length; i++) {
                json[keys[i]] = values[i];
            }
            jsonStr = JSON.stringify(json);
        }
        return jsonStr
    }
    //导出
    $('#btnExport').click(function () {
        var start = document.getElementById("start").value == "" ? "1999/01/01 00:00:00" : document.getElementById("start").value;
        var end = document.getElementById("end").value == "" ? getNowFormatDate(0) : document.getElementById("end").value;
        var form = $("<form>");
        form.attr("style", "disblay:none");
        form.attr("target", "");
        form.attr("method", "post");
        form.attr("action", "@Url.Action("ExportList")" + "?start=" + start + "&end=" + end + "&objs=" + createJsonStr());
        $("body").append(form);//将表单放置在web中
        form.submit();

    })
    function removeCondition(obj) {
        var key = $(obj).parent().children(".dropdown-toggle")[0].value;
        var value = $(obj).parent().children(".form-control")[0].value;
        keys.remove(key);
        values.remove(value);
        $(obj).parent().remove();
    }
    //laydate
    var start = {
        elem: '#start',
        format: 'YYYY/MM/DD hh:mm:ss',
        max: '2099-06-16 23:59:59', //最大日期
        istime: true,
        istoday: false,
        choose: function (datas) {
            end.min = datas; //开始日选好后，重置结束日的最小日期
            end.start = datas; //将结束日的初始值设定为开始日
        }
    };
    var end = {
        elem: '#end',
        format: 'YYYY/MM/DD hh:mm:ss',
        min: laydate.now(),
        max: '2099-06-16 23:59:59',
        istime: true,
        istoday: false,
        choose: function (datas) {
            start.max = datas; //结束日选好后，重置开始日的最大日期
        }
    };
    //laydate.skin('yalan');
    laydate(start);
    laydate(end);

    //数组去重
    function unique(array) {
        var res = [];
        var json = {};
        for (var i = 0; i < array.length; i++) {
            if (!json[array[i]]) {
                res.push(array[i]);
                json[array[i]] = 1;
            }
        }
        return res;
    }
    //当前日期
    function getNowFormatDate(day) {
        var date = new Date();
        var seperator1 = "/";
        var seperator2 = ":";
        var month = date.getMonth() + 1;
        var strDate = date.getDate() + day;
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
                + " 23:59:59";
        //var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
        //        + " " + date.getHours() + seperator2 + date.getMinutes()
        //        + seperator2 + date.getSeconds();
        return currentdate;
    }

    function getecharts(json) {
        var bar_x = new Array();
        var bar_y = new Array();
        var pie_key = new Array();
        var pie_value = new Array();
        bar_x.push("碎片"); bar_x.push("厚度偏差片"); bar_x.push("缺口,掉脚"); bar_x.push("TTV偏差整片");
        bar_x.push("杂质整片"); bar_x.push("锯痕超差片"); bar_x.push("晶粒不合格片");
        bar_x.push("A锯痕(0-20μm)"); bar_x.push("B2晶粒小"); bar_x.push("胶面B4");
        bar_x.push("B7(锯痕20～40μｍ)"); bar_x.push("B9表面少许沾污"); bar_x.push("B11色差片"); bar_x.push("B12色差片");
        bar_y.push(json[0]["Fragment"] ? json[0]["Fragment"] : 0);
        bar_y.push(json[0]["ThicknessDeviation"] ? json[0]["ThicknessDeviation"] : 0);
        bar_y.push(json[0]["Notch"] ? json[0]["Notch"] : 0);
        bar_y.push(json[0]["TTV_Offset"] ? json[0]["TTV_Offset"] : 0);
        bar_y.push(json[0]["Impurity"] ? json[0]["Impurity"] : 0);
        bar_y.push(json[0]["UnqualifiedMark"] ? json[0]["UnqualifiedMark"] : 0);
        bar_y.push(json[0]["UnqualifiedGrain"] ? json[0]["UnqualifiedGrain"] : 0);
        bar_y.push(json[0]["MarkA"] ? json[0]["MarkA"] : 0);
        bar_y.push(json[0]["B2"] ? json[0]["B2"] : 0);
        bar_y.push(json[0]["Glue"] ? json[0]["Glue"] : 0);
        bar_y.push(json[0]["MarkB7"] ? json[0]["MarkB7"] : 0);
        bar_y.push(json[0]["B9"] ? json[0]["B9"] : 0);
        bar_y.push(json[0]["B11"] ? json[0]["B11"] : 0);
        bar_y.push(json[0]["B12"] ? json[0]["B12"] : 0);
        pie_key = bar_x;
        pie_value.push(json[0]["FragmentRate"] ? json[0]["FragmentRate"] : 0);
        pie_value.push(json[0]["ThicknessDeviationRate"] ? json[0]["ThicknessDeviationRate"] : 0);
        pie_value.push(json[0]["NotchRate"] ? json[0]["NotchRate"] : 0);
        pie_value.push(json[0]["TTV_OffsetRate"] ? json[0]["TTV_OffsetRate"] : 0);
        pie_value.push(json[0]["ImpurityRate"] ? json[0]["ImpurityRate"] : 0);
        pie_value.push(json[0]["UnqualifiedMarkRate"] ? json[0]["UnqualifiedMarkRate"] : 0);
        pie_value.push(json[0]["UnqualifiedGrainRate"] ? json[0]["UnqualifiedGrainRate"] : 0);
        pie_value.push(json[0]["MarkARate"] ? json[0]["MarkARate"] : 0);
        pie_value.push(json[0]["B2Rate"] ? json[0]["B2Rate"] : 0);
        pie_value.push(json[0]["GlueRate"] ? json[0]["GlueRate"] : 0);
        pie_value.push(json[0]["MarkB7Rate"] ? json[0]["MarkB7Rate"] : 0);
        pie_value.push(json[0]["B9Rate"] ? json[0]["B9Rate"] : 0);
        pie_value.push(json[0]["B11Rate"] ? json[0]["B11Rate"] : 0);
        pie_value.push(json[0]["B12Rate"] ? json[0]["B12Rate"] : 0);
        //$('#echarts').show();
        getbar("bar", bar_x, bar_y, "生产情况对比", "数量");
        getpie("pie", pie_key, pie_value, "生产情况占比", "占比");
    }

    //柱状图
    function getbar(id, x, y, titletxt, legendtxt) {
        var myChart = echarts.init(document.getElementById(id));
        // 指定图表的配置项和数据
        var option = {
            color: ['#3398DB'],
            title: {
                text: titletxt
            },
            tooltip: { show: true, trigger: 'axis' },
            toolbox: {
                show: true,
                feature: {
                    mark: {
                        show: true
                    },
                    dataView: {
                        show: true,
                        readOnly: false
                    },
                    magicType: {
                        show: true,
                        type: ['line', 'bar']
                    },
                    restore: {
                        show: true
                    },
                    saveAsImage: {
                        show: true
                    }
                }
            },
            grid: {
                x: 40,
                x2: 100,
                y2: 150
            },
            legend: {
                data: [legendtxt]
            },
            xAxis: [{
                type: 'category',
                axisLabel: {
                    interval: 0,
                    rotate: 45,
                    margin: 2
                },
                data: x
            }],
            yAxis: {},
            series: [{
                name: legendtxt,
                type: 'bar',
                data: y
            }]
        };
        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
    }

    //饼图
    function getpie(id, names, values, titletxt, seriestxt) {
        var myChart = echarts.init(document.getElementById(id));
        var piedata = [];
        for (var i = 0; i < names.length; i++) {
            var namevalue = { "name": names[i], "value": values[i] };
            piedata.push(namevalue);
        }
        var option = {
            title: {
                text: titletxt,
                left: 'center',
                textStyle: {
                    color: '#333333'
                }
            },
            tooltip: {
                trigger: 'item',
                formatter: "{a}<br/>{b}: {c} ({d}%)"
            },
            toolbox: {
                show: true,
                feature: {
                    mark: {
                        show: true
                    },
                    dataView: {
                        show: true,
                        readOnly: false
                    },

                    restore: {
                        show: true
                    },
                    saveAsImage: {
                        show: true
                    }
                }
            },
            legend: {
                orient: 'vertical',
                x: 'left',
                data: names
            },
            series: [
                {
                    name: seriestxt,
                    type: 'pie',
                    radius: ['50%', '70%'],
                    avoidLabelOverlap: false,
                    label: {
                        normal: {
                            show: false,
                            position: 'center'
                        },
                        emphasis: {
                            show: true,
                            textStyle: {
                                fontSize: '30',
                                fontWeight: 'blod'
                            }
                        }
                    },
                    labelLine: {
                        normal: {
                            show: false
                        }
                    },
                    data: piedata
                }
            ]
        }
        myChart.setOption(option);
    }

    //配置字段
    function moveOption(e1, e2) {
        try {
            for (var i = 0; i < e1.options.length; i++) {
                if (e1.options[i].selected) {
                    var e = e1.options[i];
                    e2.options.add(new Option(e.text, e.value));
                    e1.remove(i);
                    ii = i - 1
                }
            }
            document.getElementById('configs').value = getvalue(document.getElementById('list2'));
            //document.myform.city.value = getvalue(document.myform.list2);
        }
        catch (e) { }
    }
    function getvalue(geto) {
        var allvalue = "";
        for (var i = 0; i < geto.options.length; i++) {
            allvalue += geto.options[i].value + ",";
        }
        return allvalue;
    }
</script>
<script src="~/Scripts/echarts.min.js"></script>
<script src="~/Scripts/vintage.js"></script>

